package com.sduept.bigdata.iec61850.client;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.beanit.iec61850bean.SclParser;
import com.beanit.iec61850bean.ServerModel;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.List;

/**
 * @author: lxj
 * @date: 2022/3/24 8:17
 * @since
 */
public class ServerModelParser {
    private static final  String serverModelPath = "E:\\aaa\\smcdmodel";
    public static void saveToFile(ServerModel serverModel,String address) throws IOException {
        FileUtils.write(getModelFile(address),serverModel.toString(), Charset.forName("utf-8"),false);
    }
    public static ServerModel getServerModel4File(String address) throws IOException {
       String json =  FileUtils.readFileToString(getModelFile(address),"utf-8");
       return JSON.parseObject(json,ServerModel.class);
    }
    private static File getModelFile(String address){
       return new File(serverModelPath+File.separator+ address+"_"+System.currentTimeMillis()+".txt");
    }

}
